from config.city import CITY_LIST
from submodules.common.lib.log_ import logger


def necessary_params_check(necessary_param_list, type, req, res):
    if type == "body":
        # body格式校验
        if isinstance(req.body, dict):
            pass
        else:
            res.code = 1001
            res.msg = f"body格式不正确！"
            logger.error(res.msg)
            return res
        # 必传参数校验
        for param in necessary_param_list:
            if param in req.body.keys():
                pass
            else:
                res.code = 1002
                res.msg = f"body中缺少{param}参数！"
                logger.error(res.msg)
                return res
        return True
    if type == "params":
        pass


def optional_params_check(optional_param_list, type, req, res):
    if type == "body":
        # body格式校验
        if isinstance(req.body, dict):
            pass
        else:
            res.code = 1001
            res.msg = f"body格式不正确！"
            logger.error(res.msg)
            return res
        # 必传参数校验
        for param in req.body.keys():
            if param in optional_param_list:
                pass
            else:
                res.code = 1002
                res.msg = f"{param}不在可选参数列表中！"
                logger.error(res.msg)
                return res
        return True
    if type == "params":
        pass


def get_city_name(city_id):
    for item in CITY_LIST:
        if int(city_id) == item["id"]:
            return item["name"]


def list_in_list_to_dict_in_list(list_in_list, keys):
    l1 = []
    # logger.info(list_in_list)
    for item in list_in_list:
        # logger.info(item)
        d = {}
        for i in range(len(item)):
            d[keys[i]] = str(item[i])
        l1.append(d)
    return l1


if __name__ == "__main__":
    def test_get_city_name():
        res = get_city_name(122)
        print(res)

    test_get_city_name()